<template>
  <div>
    <el-form :inline="true" :model="search" class="demo-form-inline">
     
      <el-row class="table-head-box">
         <el-col :span="4" class="flex flex-start">
          <el-button type="primary" icon="el-icon-plus"    plain @click="addServiceHandler()">添加服务</el-button>
        </el-col>
        <el-col :span="20" class="flex flex-end input-box">
          <el-input v-model="search.lkParam.service_type_name" clearable placeholder="服务名称"></el-input>
          <el-button type="primary" icon="el-icon-search" @click="searchUserHandler">查询</el-button>
        </el-col>

      </el-row>
    </el-form>
    <el-table :data="serviceList" border style="width: 100%" tooltip-effect="dark" size="mini">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column  prop="serviceTypeName" label="服务名称">
      </el-table-column>
      <el-table-column  prop="serviceTypeDesc" label="服务描述">
      </el-table-column>
      <el-table-column prop="serviceTypeIcon" label="服务标题 ">
        <template slot-scope="scope">
            <span><img :src="scope.row.serviceTypeIcon+'?imageView2/1/w/80/h/80'" width="20px" height="20px"></span>
          </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" width="300">
        <template slot-scope="scope">
          <div v-if="scope.row.status == 1">正常</div>
          <div v-if="scope.row.status == 2">无效</div>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button class="el-icon-edit" type="primary"  size="mini" @click="updateServiceHandler(scope.$index, scope.row)">编辑</el-button>
          <!-- <el-button v-if="scope.row.userName !='sys'" type="danger" size="mini" @click="deleteServiceHandler(scope.$index, scope.row)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-row>
        <el-col :span="24" style="text-align:right;">
            <el-pagination background layout="total,prev, pager, next" :current-page.sync="search.current" :page-count="search.size" :total="search.total" @current-change="sizeChangeHandler"> </el-pagination>
        </el-col>
    </el-row>
    <ServiceAdd :serviceDialog="showServiceDialog" :popService="service"  @close="closeHandler"></ServiceAdd>
  </div>
</template>
<script>
import {servicePageListUrl} from '@/utils/common'
import ServiceAdd from "./service-add";

export default {
  components: {
    ServiceAdd
  },
  data() {
    return {
      serviceList: [],
      service: null,
      showServiceDialog: false,
      userId: null,
      search: {
        current:1,
        size:10,
        total: 0,
        lkParam: {userName:""},
        eqParam:{},
      }
    };
  },
  mounted() {
    this.loadServices();
  },
  methods: {
    addServiceHandler: function () {
      this.service = {status:1};
      this.showServiceDialog = true;
    },
    updateServiceHandler: function (index, row) {
      this.service = row;
      this.showServiceDialog = true;
    },
    closeHandler: function () {
      this.showServiceDialog = false;
      this.loadServices();
    },
    /**
     * 删除用户
     */
    deleteServiceHandler: function (index, row) {
      this.$confirm("此操作将永久删除该服务, 是否继续?", "提示", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" })
        .then(() => {
          this.axios
            .post("/fc/su/del/" + row.userId)
            .then(response => {
                console.log(response)
              this.$message({ type: "success", message: "删除成功!"  });
              this.loadUsers();
            })
            .catch(response => {
                console.log(response)
              this.$message({ type: "warn", message: "删除失败!"  });
            });
        })
        .catch(() => {
          this.$message({ type: "info", message: "已取消删除" });
        });
    },
    loadServices() {
      this.axios
        .post(servicePageListUrl, this.search)
        .then(response => {
          var data = response.data.data;
          this.serviceList = data.records;
          this.search.total = data.total;
        })
        .catch(response => {
          console.log("response -   " + response);
        });
    },
    sizeChangeHandler: function (value) {
       this.search.current = value;
      this.loadServices();
    },
    searchUserHandler: function () {
      this.search.current=1
      this.loadServices();
    }
  }
};
</script>
<style scoped>
.grid-content {
  text-align: left;
  height: 45px;
}
</style>
